import bluetooth


def findDeviceAdress( deviceName ):
    deviceAddress = None
    
    nearbyDevices = bluetooth.discover_devices()
    
    for bdaddr in nearbyDevices:
        currDeviceName = bluetooth.lookup_name( bdaddr )
        if currDeviceName == deviceName:
            return bdaddr
    
    return None




def sendText( text, devName ):
    bd_addr = findDeviceAdress( devName )
    
    if bd_addr == None:
        print "couldn't find the device:", devName
        return
    else:
        print "found device:", devName
        print "the address: ", bd_addr
    
    port = 1
    
    sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
    sock.connect( (bd_addr, port) )
    
    sock.send( text )
    
    sock.close()
    
    print "sent text: ", text
